<template>
  <div class="goodInfoContainer">
    <transition
      @before-enter='beforeEnter'
      @enter='enter'
      @after-enter='afterEnter'>
      <div class="ball" v-show="ballFlag" ref='ball'></div>
    </transition>

    <!-- 轮播图区域 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <swiper :lunbolists='lunbolists' :isfull='true'></swiper>
        </div>
      </div>
    </div>
    <!-- 商品购买区域 -->
    <div class="mui-card">
      <div class="mui-card-header">商品的名称标题</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            市场价：<del>￥9999</del>&nbsp;&nbsp;销售价：<span class="now_price">￥1999</span>
          </p>
          <p>
            购买数量：<number @number='getnumber'></number>
          </p>
          <p>
            <mt-button type='primary' size='small'>立即购买</mt-button>
            <mt-button type='danger' size='small' @click="add">加入购物车</mt-button>
          </p>
        </div>
      </div>
    </div>
    <!-- 商品详情区域 -->
    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>商品货号：23121546</p>
          <p>库存情况：200件</p>
          <p>上架时间：2016-12-11 12:10:03</p>
        </div>
      </div>
      <div class="mui-card-footer">
        <mt-button type='primary' size='large' plain>图文介绍</mt-button>
        <mt-button type='danger' size='large' plain>商品评论</mt-button>
      </div>
    </div>
  </div>
</template>
<script>
import swiper from '../subVue/swiper.vue'
import number from '../subVue/number.vue'
export default {
  data(){
    return {
      lunbolists:[],
      ballFlag:false,
      number:1
    }
  },
  created(){
    this.getlunbo()
  },
  methods:{
    getnumber(data){
      this.number=parseInt(data) 
    },
    getlunbo(){
      this.$http.get('http://www.liulongbin.top:3005/api/getlunbo').then(ret=>{
        if(ret.body.status==0){
          this.lunbolists=ret.body.message
        }else{
          Toast('轮播图加载失败');
        }
      })
    },
    add(){
      this.ballFlag=!this.ballFlag
      const goodsInfo={
        id:12,
        count:this.number,
        price:'1999',
        select:true
      }
      this.$store.commit('add',goodsInfo)
    },
    beforeEnter(el){
      el.style.transform='translate(0,0)'
    },
    enter(el,done){
      el.offsetWidth;
      const ballPositin=this.$refs.ball.getBoundingClientRect();
      const iconPosition=document.getElementById('icon').getBoundingClientRect();
      const x=iconPosition.left-ballPositin.left;
      const y=iconPosition.top-ballPositin.top;
      el.style.transform=`translate(${x}px,${y}px)`;
      el.style.transition="all 0.8s cubic-bezier(.4,-0.3,1,.68)";
      done()
    },
    afterEnter(el){
      this.ballFlag=!this.ballFlag;
    }
  },
  components:{
    swiper,
    number
  }  
}
</script>
<style lang="scss" scoped>
.goodInfoContainer{
  background-color: #eee;
  overflow: hidden;
  .now_price{
    color:red;
    font-size: 16px;
    font-weight: bold;
  }
}
.mui-card-footer{
  display: block;
  button{
    margin:15px 0;
  }
}
.ball{
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: red;
  position:absolute;
  z-index: 99;
  top: 390px;
  left: 146px;
}
</style>
